package com.ruoyi.web.controller.tjfx;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tjfx.domain.TbTjfxNhdb;
import com.ruoyi.tjfx.service.ITbTjfxNhdbService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 各仪能耗对比Controller
 *
 * @author ruoyi
 * @date 2023-11-11
 */
@RestController
@RequestMapping("/tjfx/nhdb")
public class TbTjfxNhdbController extends BaseController
{
    @Autowired
    private ITbTjfxNhdbService tbTjfxNhdbService;

    /**
     * 查询各仪能耗对比列表
     */
    @PreAuthorize("@ss.hasPermi('tjfx:nhdb:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbTjfxNhdb tbTjfxNhdb)
    {
        startPage();
        List<TbTjfxNhdb> list = tbTjfxNhdbService.selectTbTjfxNhdbList(tbTjfxNhdb);
        return getDataTable(list);
    }
//    @PreAuthorize("@ss.hasPermi('tjfx:nhdb:list')")
//    @GetMapping("/listsort")
//    public TableDataInfo listyb(TbTjfxNhdb tbTjfxNhdb)
//    {
//        startPage();
//        List<TbTjfxNhdb> list = tbTjfxNhdbService.selectTbTjfxNhdbListyb(tbTjfxNhdb);
//        System.out.println(list);
//        return getDataTable(list);
//    }

    /**
     * 导出各仪能耗对比列表
     */
    @PreAuthorize("@ss.hasPermi('tjfx:nhdb:export')")
    @Log(title = "各仪能耗对比", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTjfxNhdb tbTjfxNhdb)
    {
        List<TbTjfxNhdb> list = tbTjfxNhdbService.selectTbTjfxNhdbList(tbTjfxNhdb);
        ExcelUtil<TbTjfxNhdb> util = new ExcelUtil<TbTjfxNhdb>(TbTjfxNhdb.class);
        util.exportExcel(response, list, "各仪能耗对比数据");
    }

    /**
     * 获取各仪能耗对比详细信息
     */
    @PreAuthorize("@ss.hasPermi('tjfx:nhdb:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbTjfxNhdbService.selectTbTjfxNhdbById(id));
    }

    /**
     * 新增各仪能耗对比
     */
    @PreAuthorize("@ss.hasPermi('tjfx:nhdb:add')")
    @Log(title = "各仪能耗对比", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTjfxNhdb tbTjfxNhdb)
    {
        return toAjax(tbTjfxNhdbService.insertTbTjfxNhdb(tbTjfxNhdb));
    }

    /**
     * 修改各仪能耗对比
     */
    @PreAuthorize("@ss.hasPermi('tjfx:nhdb:edit')")
    @Log(title = "各仪能耗对比", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTjfxNhdb tbTjfxNhdb)
    {
        return toAjax(tbTjfxNhdbService.updateTbTjfxNhdb(tbTjfxNhdb));
    }

    /**
     * 删除各仪能耗对比
     */
    @PreAuthorize("@ss.hasPermi('tjfx:nhdb:remove')")
    @Log(title = "各仪能耗对比", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbTjfxNhdbService.deleteTbTjfxNhdbByIds(ids));
    }
}
